{include file="public/header"}
<body>
<script src="/static/global/drag/Sortable.min.js"></script>
<script src="/static/global/drag/vuedraggable.umd.min.js"></script>
<div id="app" v-cloak>
    <div class="ht-main">
        <div class="ht-search">
            <el-form :inline="true" size="small">
                <el-form-item label="名称">
                    <el-input type="text" placeholder="矿区名称" v-model="searchKey.title"></el-input>
                </el-form-item>
                <el-form-item label="编号">
                    <el-input type="text" placeholder="矿区编号" v-model="searchKey.no"></el-input>
                </el-form-item>
                <el-form-item label="联系人">
                    <el-input type="text" placeholder="联系人" v-model="searchKey.name"></el-input>
                </el-form-item>
                <el-form-item label="电话">
                    <el-input type="text" placeholder="电话" v-model="searchKey.tel"></el-input>
                </el-form-item>
                <el-form-item label="状态">
                    <el-select v-model="searchKey.status" placeholder="请选择">
                        <el-option label="全部" value=""></el-option>
                        <el-option label="启用" :value="1"></el-option>
                        <el-option label="禁用" :value="-1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="success" icon="el-icon-search" @click="search">搜索</el-button>
                    <el-button type="" icon="el-icon-refresh" @click="reset">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="ht-tool">
            <div class="ht-tool-left">
               <el-button type="success" size="mini" icon="el-icon-plus" @click="doAdd">添加</el-button>
               <el-button type="primary" :disabled="tableSelect.length !== 1" size="mini" icon="el-icon-edit"
                          @click="edit(tableSelect[0])">编辑
               </el-button>
                <el-button type="danger" :disabled="!tableSelect.length" size="mini" icon="el-icon-delete"
                           @click="batchDel('/admin/diggings/del')">删除
                </el-button>
            </div>
            <div class="ht-tool-right">
            </div>
        </div>
        <div class="ht-main-body">
            <el-table :data="tableData" border header-row-class-name="ht-table-header"
                      ref="dataTable" @selection-change="handleSelectChange" row-key="title"
            >
                <el-table-column align="center" type="selection" width="39"></el-table-column>
                <el-table-column align="center" width="100px" prop="id" label="ID"></el-table-column>
                <el-table-column align="center" prop="no" label="矿区ID"></el-table-column>
                <el-table-column align="center" prop="title" label="矿区名称"></el-table-column>
                <el-table-column align="center" prop="address" label="矿区地址"></el-table-column>
                <el-table-column align="center" prop="name" label="联系人"></el-table-column>
                <el-table-column align="center" prop="tel" label="电话"></el-table-column>
                <el-table-column align="center" prop="status" label="状态">
                    <template slot-scope="scope">
                        <el-switch
                                v-model="scope.row.status"
                                active-color="#13ce66"
                                inactive-color="#eeeeee"
                                @change="changeStatus($event,scope.row.id)"
                                :active-value="1"
                                :inactive-value="-1">
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column align="center" width="180" prop="create_time" label="添加时间"></el-table-column>
                <el-table-column
                        align="center"
                        label="操作"
                        width="180">
                    <template slot-scope="scope">
                        <el-button @click="edit(scope.row)" size="mini" type="primary" icon="el-icon-edit"></el-button>
                        <el-button @click="del(scope.row)" size="mini" type="danger" icon="el-icon-delete"></el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="ht-main-page">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="page"
                        :page-sizes="[1,10, 200, 300, 400]"
                        :page-size="limit"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>
            <el-drawer
                    :visible.sync="is_edit"
                    size="80%"
                    :with-header="false"
                    custom-class="ht-drawer-bg"
                    :append-to-body="true"
                    :destroy-on-close="true"
            >
                <div class="ht-drawer-main">
                    <el-page-header @back="goBack" title="Esc返回" :content="content"></el-page-header>
                    <div class="ht-form">
                        <el-form :model="editData" label-width="120px" size="small">
                            <!-- <el-form-item label="图标"> -->
                            <!--     <el-input placeholder="图标" v-model="editData.image" style="width: 70%"></el-input> -->
                            <!--     <el-button @click="imageOpen()" size="small" type="primary">选择</el-button> -->
                            <!-- </el-form-item> -->
                            <!-- <el-form-item v-if="editData.image"> -->
                            <!--     <img :src="editData.image" class="ht-image100" @click="showImg(editData.image)"> -->
                            <!-- </el-form-item> -->
                            <el-form-item label="矿区ID">
                                <el-input placeholder="矿区ID" v-model="editData.no"></el-input>
                            </el-form-item>
                            <el-form-item label="矿区名称">
                                <el-input placeholder="矿区名称" v-model="editData.title"></el-input>
                            </el-form-item>
                            <el-form-item label="矿区地址">
                                <el-input placeholder="矿区地址" v-model="editData.address"></el-input>
                            </el-form-item>
                            <el-form-item label="联系人">
                                <el-input placeholder="联系人" v-model="editData.name"></el-input>
                            </el-form-item>
                            <el-form-item label="电话">
                                <el-input placeholder="电话" v-model="editData.tel"></el-input>
                            </el-form-item>
                            <el-form-item>
                                <el-button @click="goBack">取消</el-button>
                                <el-button type="primary" @click="onSubmit" :loading="is_loading">提交</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
            </el-drawer>
        </div>

    </div>
</div>
{include file="public/common"}
<script>
    let vs ;
    let del_url = "{:url('diggings/del')}";
    let add_url = "{:url('diggings/add')}";
    let index_url = "{:url('diggings/index')}";
    var vm = new Vue({
        el: "#app",
        data: function () {
            return {
                showDialog: false,
                arctypeList: [],
                activeTab: 'first',
                tableData: [],
                is_edit: false,
                editData: {},
                editDataTemp: {},
                content: '编辑',
                total: 0,
                page: 1,
                limit: 10,
                userList: [],
                sourceList: [],
                regionList: [],
                phpList:[],
                fileManage:false,
                enterpriseList:[],
                imageList:[]
            }
        },
        created: function () {
            vs = this;
            this.getData()
        },
        methods: {
            handleRemove(item,index) {
                vs.editData.images.splice(index,1)
                console.log(vs.editData.images)
                vs.$forceUpdate()
            },
            imageManageClose(path) {
                this.showDialog = false;
            },
            imageSubmit(path) {
                console.log("path", path)
                vs.editData.image = path[0]
                vs.showDialog = false;
            },
            imageManage() {
                this.showDialog = true;
            },
            uploadSuccess(litpic, value) {
                this.editDataTemp.litpic = litpic
                this.editData.litpic = litpic
            },
            changeStatus(e,id) {
                Api.request("{:url('diggings/setStatus')}", {id:id,status:e}).then((res)=>{
                    this.$message({
                        message:'操作成功',
                        type:'success',
                        duration:1000,
                    })
                })
            },
            onSubmit() {
                var that = this
                $.post(add_url, that.editData, function (res) {
                    if (res.code == 1) {
                        that.showSuccessMsgCall(function () {
                            that.is_edit = false;
                            that.showDialog = false;
                            that.editData = {};
                            that.getData()
                        })
                    } else {
                        that.showErrorMsg(res.msg)
                    }
                })
            },
            getData: function () {
                var that = this
                that.searchType = {
                    title: 'like',
                    no: 'like',
                    name: 'like',
                };
                if (vs.searchKey.create_time) {
                    if (vs.searchKey.create_time[1].indexOf('23:59:59') === -1) {
                        vs.searchKey.create_time[1] = vs.searchKey.create_time[1] + " 23:59:59"
                    }
                }
                $.post(index_url, {
                    limit: that.limit,
                    page: that.page,
                    search_key: that.searchKey,
                    search_type: that.searchType
                }, function (res) {
                    if (res.code == 1) {
                        that.tableData = res.data.data
                        that.total = res.data.total
                    } else {
                        that.showErrorMsg(res.msg)
                    }
                })
            },
            doAdd: function () {
                this.is_edit = true
                this.content = '添加'
                this.editData = {region_id:0}
            },
            edit: function (data) {
                this.is_edit = true
                this.content = '编辑'
                this.editData = data

                console.log(data)
            },
            goBack: function () {
                this.is_edit = false
            },
            del: function (data) {
                var that = this
                that.$confirm('确定删除么?', '提示', {
                    type: 'warning',
                    lockScroll: false
                }).then(() => {
                    $.post(del_url, {id: data.id}, function (res) {
                        if (res.code == 1) {
                            that.showSuccessMsgCall(function () {
                                that.getData()
                            })
                        } else {
                            that.showErrorMsg(res.msg)
                        }
                    })
                })
            },
            handleSizeChange: function (e) {
                this.limit = e
            },
            handleCurrentChange: function (e) {
                this.page = e
            }
        },
        watch: {
            page(v) {
                this.getData()
            },
            limit() {
                this.getData()
            }
        }
    })
</script>
</body>
</html>
